This invention relates generally to the field of memory management and in particular to a dynamic cache management mechanism for a computer program.
A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever. The following notice applies to the software and data as described below and in the drawing hereto: Copyright(copyright)1998, Microsoft Corporation, All Rights Reserved.
Many application programs are configured at the time they are initially loaded and set up to run on a computer system. The amount of memory available for use by the program is one of the things that is configured at set up time. It is sometimes difficult for a computer user to anticipate how much memory an application will require in order to run, not to mention run efficiently and quickly. Some applications, such as data base language servers run faster only with a significant amount of memory, referred to as a buffer or cache. The cache is used to store both executable code related to running the program as well as data that is used by the program, in this case, multiple tables of a database. Further, the amount of data that such a program is processing affects the amount of memory needed to run well. The amount of data that the program is processing can also vary over time, thus increasing or decreasing the amount of memory needed to run well. The amount of memory configured for use by such a program also depends on the size of the machine and amount of memory available on the machine. Some have very large amounts of memory, while others have less. Configuring the program that likes more memory with too much or too little memory for the system on which it is running can result in suboptimal performance of the system.
Once an application is allocated a certain amount of memory in the system to use, the operating system takes over management of the physical main memory. It commits real or physical main memory to the memory of the application. Many times, the operating system must take real memory from one application and associate it with a buffer for another application. It usually takes that memory in an amount equal to one or more pages, where a page is a certain amount of data, such as four kilobytes. When it takes a page to give to another system, it must write the data on that page to secondary storage, which is usually slower than the main memory. When the application needs to access that data again, it must first be paged back in again, which can take a large amount of time as compared to the speed at which programs normally run with data in memory.
There is a need to avoid such paging as much as possible for selected applications, such as data base applications, where many users expect and demand sub second response times. If the data, or code to provide the functionality requested by a user or another program is not currently in the memory, it significantly degrades the performance of the application. Again, suboptimal performance can result if too little memory is available to a memory intensive application because data must be continually retrieved from secondary storage. However, suboptimal performance can also result from a memory intensive application being set up with too much memory, since the operating system will start paging out the data needed by the application, again resulting in data being continually retrieved from secondary storage.
There is a need for a mechanism to better manage the amount of memory that is available to application programs. Such a mechanism should be simple to use, and not require a user, who may not have relevant experience and ability, to set up or modify the memory resources allocated to the programs. Further, the resources used by the program should not adversely affect the overall performance and integrity of the computer system on which the program is running.
A dynamic cache management mechanism determines the amount of memory available from a system on which a memory intensive application is running and dynamically manages the amount of cache for which real memory is associated or committed by the system.
In one embodiment, the memory intensive application uses a background thread to periodically query a memory manager, normally a part of an operating system, to determine how much memory is available for use by applications. If the amount of memory, as identified in a free list is above a predetermined threshold, the application requests more memory for its use. If below the predetermined threshold, the application gives memory back to the operating system so it may be used by the operating system or other applications and programs. A temporal average of the number of available pages from the operating system is used to prevent oscillation of the size of the memory allocated to the application.
The threshold used by the application is determined to be a desired amount above a known basic operating system desired amount. The difference between the threshold and the reserved amount is referred to as an excess over the desired amount. The existence of the excess allows other applications to also obtain memory resources. This allows other applications the ability to run while at the same time maximizing the amount of memory allocated to the application using the mechanism.
In one embodiment, the application comprises a database system. Dynamically expanding or contracting the database system cache based upon system demand allows the database system data cache to expand and shrink based upon system demand for memory, optimizing the use of physical system memory and providing better performance of the database. This benefit is provided even though the size of the database being used changes over time. Users of the application need not be familiar with the complexities involved in configuring the memory to meet the requirements of the database system. Further, other applications will also run efficiently because the excess memory will be made available by the memory intensive application for their use as the demands on the system resources expand and contract over time.